<script lang="ts" setup>
import { PageSkip } from '@/utils/tools'
const props = defineProps<{
  list: any[]
}>()

const emit = defineEmits<{
  (event: 'openPopup', item: any): void
}>()
const statusMap = <any>{
  // 4待开始、2已使用、3已过期、2已核销、0已失效
  0: '已失效',
  3: '已过期',
}
/**处理水印文字 */
function handleText(i: any) {
  if (i.type === 6) {
    return statusMap[i.status] || '已核销'
  } else {
    return statusMap[i.status] || '已使用'
  }
}
/**根据优惠券类型进行处理 */
const handleToUse = (i: any) => {
  if (i.type === 6) {
    // 去核销
    emit('openPopup', i)
  } else {
    PageSkip('/pages/eat/eat', 'switchTab')
  }
}
</script>
<template>
  <view class="center">
    <view
      class="_item"
      :style="{
        filter: item.status === 1 || item.status === 4 ? `grayscale(0%)` : `grayscale(100%)`,
      }"
      v-for="item in props.list"
      :key="item.id"
    >
      <view class="couponsType" :style="{ background: item.type === 6 ? '#FFB52C' : '#8adf4b' }">
        {{ item.type === 6 ? '实体券' : '优惠券' }}</view
      >

      <view class="content">
        <view class="couponsName">{{ item.couponName }}</view>
        <view v-show="item.status === 1 || item.status === 4" class="endTime">{{
          `有效期至${item.validEndTime}`
        }}</view>
        <view class="getTime">{{ `获得时间：${item.createTime}` }}</view>
      </view>

      <button
        class="toUse"
        @tap.stop="handleToUse(item)"
        v-if="item.status === 1 || item.status === 4"
        :style="{ background: item.type === 6 ? '#FFB52C' : '#8adf4b' }"
      >
        {{ item.type === 6 ? '去核销' : '去使用' }}
      </button>
      <!-- 水印 -->
      <view v-else class="watermark">
        <view class="watermarkText">{{ handleText(item) }}</view>
      </view>
      <image class="xian" src="/static/images/xian.png" mode="scaleToFill" />
    </view>
  </view>
</template>
<style lang="scss" scoped>
.center {
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  ._item {
    position: relative;
    width: 702rpx;
    height: 212rpx;
    border-radius: 16rpx;
    background: #fff;
    margin-bottom: 28rpx;
    .content {
      position: absolute;
      top: 0rpx;
      left: 56rpx;
      width: 432rpx;
      height: 100%;
      padding: 0 0 0 20rpx;
      display: flex;
      flex-direction: column;
      justify-content: center;
      font-size: 20rpx;
      .couponsName {
        color: #000;
        font-family: 'PingFang SC';
        font-size: 30rpx;
        margin-bottom: 20rpx;
      }
      .endTime {
        width: 280rpx;
        height: 36rpx;
        line-height: 36rpx;
        border-radius: 8rpx;
        background: #eafbdd;
        color: rgba(0, 0, 0, 0.5);
        font-family: 'PingFang SC';
        padding: 0 16rpx;
        margin-bottom: 14rpx;
      }
      .getTime {
        color: rgba(0, 0, 0, 0.5);
        font-family: 'PingFang SC';
      }
    }
    .couponsType {
      writing-mode: vertical-lr;
      letter-spacing: 20rpx;
      width: 56rpx;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      text-align: center;
      color: #fff;
      font-family: 'PingFang SC';
      font-size: 30rpx;
      border-radius: 16rpx 0px 0px 16rpx;
      background: #8adf4b;
      padding-top: 20rpx;
    }
    .toUse {
      position: absolute;
      right: 20rpx;
      top: 50%;
      transform: translateY(-50%);
      min-width: 128rpx;
      height: 54rpx;
      line-height: 54rpx;
      color: #fff;
      background: #8adf4b;
      border-radius: 40rpx;
      font-family: 'PingFang SC';
      font-size: 24rpx;
    }
    .xian {
      position: absolute;
      right: 188rpx;
      top: 50%;
      width: 24rpx;
      height: 230rpx;
      transform: translateY(-50%);
    }

    .watermark {
      position: absolute;
      right: 40rpx;
      bottom: 28rpx;
      background: url('/static/images/watermark1.png');
      background-size: cover;
      background-position: center;
      width: 120rpx;
      height: 120rpx;
      line-height: 120rpx;
      text-align: center;
      z-index: 999;
      color: #c2c3c6;
      font-family: 'PingFang SC';
      font-size: 32rpx;
      .watermarkText {
        transform: rotate(-30deg);
      }
    }
  }
}
</style>
